package com.ruoyi.animal.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.animal.service.IAnimalInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.animal.domain.WasteManagement;
import com.ruoyi.animal.service.IWasteManagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 废弃物处理Controller
 * 
 * @author gw
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/management")
public class WasteManagementController extends BaseController
{
    @Autowired
    private IWasteManagementService wasteManagementService;

    @Autowired
    private IAnimalInformationService animalInformationService;

    /**
     * 查询废弃物处理列表
     */
    @RequiresPermissions("animal:management:list")
    @GetMapping("/list")
    public TableDataInfo list(WasteManagement wasteManagement)
    {
        startPage();
        List<WasteManagement> list = wasteManagementService.selectWasteManagementList(wasteManagement);
        for (WasteManagement wasteManagement1 : list) {
            wasteManagement1.setAnimalNumber(animalInformationService.selectAnimalInformationByAnimalId(wasteManagement1.getAnimalId()).getAnimalNumber());
        }
        return getDataTable(list);
    }

    /**
     * 导出废弃物处理列表
     */
    @RequiresPermissions("animal:management:export")
    @Log(title = "废弃物处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WasteManagement wasteManagement)
    {
        List<WasteManagement> list = wasteManagementService.selectWasteManagementList(wasteManagement);
        ExcelUtil<WasteManagement> util = new ExcelUtil<WasteManagement>(WasteManagement.class);
        util.exportExcel(response, list, "废弃物处理数据");
    }

    /**
     * 获取废弃物处理详细信息
     */
    @RequiresPermissions("animal:management:query")
    @GetMapping(value = "/{wasteId}")
    public AjaxResult getInfo(@PathVariable("wasteId") Long wasteId)
    {
        return success(wasteManagementService.selectWasteManagementByWasteId(wasteId));
    }

    /**
     * 新增废弃物处理
     */
    @RequiresPermissions("animal:management:add")
    @Log(title = "废弃物处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WasteManagement wasteManagement)
    {
        return toAjax(wasteManagementService.insertWasteManagement(wasteManagement));
    }

    /**
     * 修改废弃物处理
     */
    @RequiresPermissions("animal:management:edit")
    @Log(title = "废弃物处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WasteManagement wasteManagement)
    {
        return toAjax(wasteManagementService.updateWasteManagement(wasteManagement));
    }

    /**
     * 删除废弃物处理
     */
    @RequiresPermissions("animal:management:remove")
    @Log(title = "废弃物处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wasteIds}")
    public AjaxResult remove(@PathVariable Long[] wasteIds)
    {
        return toAjax(wasteManagementService.deleteWasteManagementByWasteIds(wasteIds));
    }
}
